package com.gitee.faster.webdav.kernel.model;

import jakarta.xml.bind.annotation.*;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.Collections;
import java.util.List;

/**
 * @author hongda.li
 */
@SuppressWarnings("SpellCheckingInspection")
@Data
@Accessors(chain = true)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
        "removeOrSet"
})
@XmlRootElement(name = "propertyupdate")
public class PropPatch {

    @XmlElements({
            @XmlElement(name = "remove", type = Remove.class),
            @XmlElement(name = "set", type = Set.class)
    })
    private List<Object> removeOrSet;

    public List<Set> filterSetList() {
        if (this.removeOrSet != null) {
            return this.removeOrSet.stream()
                    .filter(item -> item instanceof Set)
                    .map(Set.class::cast)
                    .toList();
        } else {
            return Collections.emptyList();
        }
    }

    public List<Remove> filterRemoveList() {
        if (this.removeOrSet != null) {
            return this.removeOrSet.stream()
                    .filter(item -> item instanceof Remove)
                    .map(Remove.class::cast)
                    .toList();
        } else {
            return Collections.emptyList();
        }
    }
}
